<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">开始日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="begin_date" id="date1" autocomplete="off" class="layui-input" lay-key="12">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">结束日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="end_date" id="date2" autocomplete="off" class="layui-input" lay-key="12">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>



        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<% include("/public/ajax.html"){} %>
<script>
    layui.use(['form', 'table','miniPage','element'], function () {
        var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                miniPage = layui.miniPage;

        table.render({
            elem: '#currentTableId',
            url: '/log/ajax/list',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 50, fixed: "left"},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'request_path', minWidth: 100, title: '请求路径'},
                {field: 'request_ip', minWidth: 100, title: '请求ip'},
                {field: 'request_time', minWidth: 100, title: '请求时间'},
                {title: '操作', minWidth: 50, toolbar: '#currentTableBar', fixed: "right", align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: data.field
            }, 'data');

            return false;
        });




        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            //console.log(data);
            if (obj.event === 'edit') {

                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        url: '/log/ajax/del?id='+data.id,
                        success: function (result) {
                            layer.msg(result.msg);
                            if(result.code == 0) {
                                obj.del();
                            }

                        },
                        error:function(err){
                            layer.alert(err.responseJSON.msg, {icon: 5});
                        }

                    });

                    layer.close(index);
                });
            }
        });

    });
</script>